package com.example.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
@ConfigurationProperties(prefix = "zhihu")
public class CookieConfig {
    private Map<String, String> cookie = new HashMap<>();

    public Map<String, String> getCookie() {
        Map<String, String> resMap = new HashMap<>();

        for (String key : cookie.keySet()) {
            String value = cookie.get(key);
            String[] list = value.split("z_c0=");
            if (list.length > 1) {
                resMap.put(list[0], value.replace(list[0], ""));
            } else {
                resMap.put(key, value);
            }
        }

        return resMap;
    }

    public void setCookie(Map<String, String> cookie) {
        this.cookie = cookie;
    }
}
